package com.jcfk.eam.controller.bd;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.eam.domain.dto.base.EamSopStandardImgDTO;
import com.jcfk.eam.domain.query.base.EamSopStandardImgQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.eam.service.base.EamSopStandardImgService;

import java.util.List;

/**
 * 标准作业规程图片
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-08-08
 */
@Api(tags = {"标准作业规程图片管理"})
@RestController
@RequestMapping("eamsopstandardimg")
public class EamSopStandardImgController {
    @Autowired
    private EamSopStandardImgService eamSopStandardImgService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamSopStandardImgQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询标准作业规程图片")
    @PostMapping("/queryByPage")
    public RetPage<EamSopStandardImgDTO> queryByPage(@RequestBody ReqPageParam<EamSopStandardImgQuery> requestParam) {
        DataPage<EamSopStandardImgDTO> page = new DataPage<EamSopStandardImgDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamSopStandardImgDTO.class);
        page = eamSopStandardImgService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }

    /**
     * 获取附件列表
     * @return
     */
    @GetMapping("/getList/{standardId}")
    public RetResult<List<EamSopStandardImgDTO>> getList(@PathVariable("standardId") String standardId){
        EamSopStandardImgQuery query=new EamSopStandardImgQuery();
        query.setStandardId(standardId);
        List<EamSopStandardImgDTO> list=eamSopStandardImgService.getList(query);

        return RetResult.ok(list);
    }


    /**
     *  标准作业规程图片
     * 根据id 查询详情
     */
    @ApiOperation("查询标准作业规程图片")
    @GetMapping("/get/{id}")
    public RetResult<EamSopStandardImgDTO> get(@PathVariable("id") String id) {
            EamSopStandardImgDTO item = eamSopStandardImgService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理标准作业规程图片
     */
    @ApiOperation("保存标准作业规程图片")
    @PostMapping("/save")
    @RequestLogHeader(modular = "标准作业规程图片管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamSopStandardImgDTO eamSopStandardImg) {
        // 数据校验
        RetResult ret = eamSopStandardImgService.isValid(eamSopStandardImg);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamSopStandardImg.getId())){
            // 新增
            eamSopStandardImgService.insert(eamSopStandardImg);
        } else{
            // 更新
            eamSopStandardImgService.update(eamSopStandardImg);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除标准作业规程图片
     */
    @ApiOperation("批量删除标准作业规程图片")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "标准作业规程图片管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamSopStandardImgDTO eamSopStandardImg) {
        return RetResult.ok(eamSopStandardImgService.logicDeleteList(eamSopStandardImg));
    }

    /**
     *  删除标准作业规程图片
     */
    @ApiOperation("删除标准作业规程图片")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "标准作业规程图片管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamSopStandardImgService.deleteitem(id);
        return RetResult.ok();
    }
}
